package com.htx.zqs.blesmartmask.ui.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.htx.zqs.blesmartmask.bean.EventBean;
import com.htx.zqs.blesmartmask.utils.EventBusUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.ButterKnife;

/**
 * Created by KomoriWu
 * on 2019/2/17.
 */


public abstract class BaseFragment extends Fragment {
    public static final String TAG = BaseFragment.class.getSimpleName();
    public Activity activity;

    public abstract void init();

    protected abstract int getLayoutId();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), container, false);
        activity = getActivity();
        ButterKnife.inject(this, view);
        if (isRegisterEvent()) {
            EventBusUtil.register(this);
        }
        init();
        return view;
    }

    public boolean isRegisterEvent() {
        return false;
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBusUtil.unregister(this);
    }


    @Subscribe
    public void onEventMainThread(EventBean eventBean) {
        if (eventBean != null) {
            onEventReceive(eventBean);
        }
    }

    public void onEventReceive(EventBean eventBean) {

    }
}
